﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace xiaoxiong.KYJControllersLib
{
    [DefaultEvent("DeviceControlEvent")]
    public partial class DeviceControl : UserControl
    {

        public DeviceControl()
        {
            InitializeComponent();
        }

        private string deviceName;

        [Browsable(true)]
        [Category("自定义属性")]
        [Description("设置获取设备名称")]
        public string DeviceName
        {
            get { return deviceName; }
            set
            {
                deviceName = value;
                this.lbl_Title.Text = deviceName;
            }
        }

        private byte deviceState;


        [Browsable(true)]
        [Category("自定义属性")]
        [Description("设置获取设备名称")]
        public byte DeviceState
        {
            get { return deviceState; }
            set
            {
                deviceState = value;
                this.deviceState1.State = deviceState;
            }
        }

        [Browsable(true)]
        [Category("自定义事件")]
        [Description("设备操作事件")]
        public event EventHandler DeviceControlEvent;



        [Browsable(true)]
        [Category("自定义属性")]
        [Description("打开设备变量地址")]
        public string OpenAddress { get; set; }


        [Browsable(true)]
        [Category("自定义属性")]
        [Description("关闭设备变量地址")]
        public string CloseAddress { get; set; }

        [Browsable(true)]
        [Category("自定义属性")]
        [Description("设备状态的变量地址")]
        public string StateAddress { get; set; }

        private void btn_Start_Click(object sender, EventArgs e)
        {
            if (DeviceControlEvent != null)
            {
                DeviceControlEvent?.Invoke(this.OpenAddress, e);
            }
        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            if (DeviceControlEvent != null)
            {
                DeviceControlEvent?.Invoke(this.CloseAddress, e);
            }
        }
    }
}
